
<script type="text/javascript">

</script>
<style media="screen">
  .cust{
    width: 40% !important;
    float: left!important;
  }
</style>

<br>
<div class="ui  container">
  <div class="ui segment">
    <div class="ui huge header">
      商品分类管理
    </div>
    <form class="" action="/webadmin/category/deletecategories" method="post">
      <div class="ui buttons">
        <a href="/system/categories/new" class="ui green basic button">增加</a>
        <button type="submit" class="ui basic red button">批量删除</button>
        <input type="hidden" name="ids" value="" id="categories_delete">
      </div>
    </form>
  </div>
  <div class="ui segment">
    <table class="ui celled table">
      <thead>
        <tr><th width="100">
          全选／反选 <br>
          <div class="ui master checkbox">
            <input type="checkbox">
            <label for=""></label>
          </div>
        </th>
        <th>名称</th>
        <th>上级</th>
        <th>操作</th>
      </tr></thead>
      <tbody>
        <% if @categories.length > 0 and @categories %>
        <% @categories.each do |category| %>
        <tr>
          <td>
            <div class="ui child checkbox" categoryid="<%= category.id %>">
              <input type="checkbox" tabindex="0">
              <label for=""></label>
            </div>
          </td>
          <td><%= category.name %> || <%= category.id %></td>
          <td>
            <%=category.category.name if category.category %>
          </td>
          <td>
            <div class="ui buttons">
              <a class="ui edit icon button" href="/system/categories/edit">编辑</a>
              <a onclick="return confirm('是否确认删除?')" class="ui edit icon button" href="/system/categories/delete/<%=category.id %>">删除</a>
            </div>
          </td>
        </tr>
        <% end %>
        <% else %>
          <p>暂时没有数据</p>
        <% end %>
      </tbody>
      <tfoot>
        <tr><th colspan="4">
          <?php echo $pagination; ?>
        </th>
      </tr></tfoot>
    </table>
  </div>
</div>
<script type="text/javascript">
$('.master.checkbox')
.checkbox({
  // check all children
  onChecked: function() {
    var
      $childCheckbox  = $('.child.checkbox');
    ;
    $childCheckbox.checkbox('check');
  },
  // uncheck all children
  onUnchecked: function() {
    var
      $childCheckbox  = $('.child.checkbox');
    ;
    $childCheckbox.checkbox('uncheck');
  }
})
;
var ids = '';
$('.child.checkbox').each(function(){
    var id = $(this).attr('categoryid');
    $(this).checkbox({
      'onChecked': function(){
        ids = ids+ id+ "|";
        $("#categories_delete").val(ids);

      },
      'onUnchecked': function(){
        var regx = new RegExp(id+'\\|');
        ids = ids.replace(regx, '');

        $("#categories_delete").val(ids);
        if (ids=='') {
          $('.master.checkbox').checkbox('uncheck');
        }
      }
    });
});
</script>
